how to implement encapsulation in javascript